package cn.com.yiqi.wsc.util;

import cn.com.yiqi.wsc.dao.appparam.entity.AppParamEntity;
import cn.com.yiqi.wsc.service.sysparams.dataobject.AppParamDO;
import cn.com.yiqi.wsc.service.sysparams.dataobject.SignRuleItem;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author 杨贵森
 * @ClassName:AppParamUtil
 * @Title: AppParamUtil
 * @Description: TODO
 * @date 2017/3/15
 */
public class AppParamUtil {


    public static  List<AppParamEntity> productSYSAppParamEntity(AppParamDO appParamDO){

        List<AppParamEntity> appParamEntityList = new ArrayList<>();

        if(appParamDO.getType().equals("SYS")){
            AppParamEntity appSYSParamEntity1 = new AppParamEntity();
            appSYSParamEntity1.setCode("SYS_LOGO");
            appSYSParamEntity1.setValue(appParamDO.getSysLogo());
            appParamEntityList.add(appSYSParamEntity1);

            AppParamEntity appSYSParamEntity2 = new AppParamEntity();
            appSYSParamEntity2.setCode("SYS_TITLE");
            appSYSParamEntity2.setValue(appParamDO.getSysTitle());
            appParamEntityList.add(appSYSParamEntity2);

            AppParamEntity appSYSParamEntity3 = new AppParamEntity();
            appSYSParamEntity3.setCode("SYS_QQ");
            appSYSParamEntity3.setValue(appParamDO.getSysQQ());
            appParamEntityList.add(appSYSParamEntity3);
        }

        if(appParamDO.getType().equals("POINT")){
            AppParamEntity appPointParamEntity1 = new AppParamEntity();
            appPointParamEntity1.setCode("POINT_RATE");
            appPointParamEntity1.setValue(appParamDO.getPointRate());
            appParamEntityList.add(appPointParamEntity1);

            AppParamEntity appPointParamEntity2 = new AppParamEntity();
            appPointParamEntity2.setCode("POINT_MAX");
            appPointParamEntity2.setValue(appParamDO.getPointMax());
            appParamEntityList.add(appPointParamEntity2);

            AppParamEntity appPointParamEntity3 = new AppParamEntity();
            appPointParamEntity3.setCode("POINT_MIN");
            appPointParamEntity3.setValue(appParamDO.getPointMin());
            appParamEntityList.add(appPointParamEntity3);

            AppParamEntity appPointParamEntity4 = new AppParamEntity();
            appPointParamEntity4.setCode("POINT_TOTALMAX");
            appPointParamEntity4.setValue(appParamDO.getPointTotalMax());
            appParamEntityList.add(appPointParamEntity4);

            AppParamEntity appPointParamEntity5 = new AppParamEntity();
            appPointParamEntity5.setCode("POINT_TOTALTIME");
            appPointParamEntity5.setValue(appParamDO.getPointTotalTime());
            appParamEntityList.add(appPointParamEntity5);

            AppParamEntity appPointParamEntity6 = new AppParamEntity();
            appPointParamEntity6.setCode("POINT_EXTRAMIN");
            appPointParamEntity6.setValue(appParamDO.getPointExtraMin());
            appParamEntityList.add(appPointParamEntity6);


            AppParamEntity appPointParamEntity7 = new AppParamEntity();
            appPointParamEntity7.setCode("POINT_EXTRAMAX");
            appPointParamEntity7.setValue(appParamDO.getPointExtraMax());
            appParamEntityList.add(appPointParamEntity7);

            AppParamEntity appPointParamEntity8 = new AppParamEntity();
            appPointParamEntity8.setCode("POINT_TOTAL_UNIT");
            appPointParamEntity8.setValue(appParamDO.getPointTotalUnit());
            appParamEntityList.add(appPointParamEntity8);

            AppParamEntity appPointParamEntity9 = new AppParamEntity();
            appPointParamEntity9.setCode("POINT_TIME_UNIT");
            appPointParamEntity9.setValue(appParamDO.getPointTimeUnit());
            appParamEntityList.add(appPointParamEntity9);

        }


        if(appParamDO.getType().equals("BALANCE")){
            AppParamEntity appBalanceParamEntity1 = new AppParamEntity();
            appBalanceParamEntity1.setCode("BALANCE_FETCH_TIMES");
            appBalanceParamEntity1.setValue(appParamDO.getBalanceEftchTimes());
            appParamEntityList.add(appBalanceParamEntity1);

            AppParamEntity appBalanceParamEntity2 = new AppParamEntity();
            appBalanceParamEntity2.setCode("BALANCE_FETCH_MAX");
            appBalanceParamEntity2.setValue(appParamDO.getBalanceEftchMax());
            appParamEntityList.add(appBalanceParamEntity2);

            AppParamEntity appBalanceParamEntity3 = new AppParamEntity();
            appBalanceParamEntity3.setCode("BALANCE_FETCH_MIN");
            appBalanceParamEntity3.setValue(appParamDO.getBalanceEftchMin());
            appParamEntityList.add(appBalanceParamEntity3);

            AppParamEntity appBalanceParamEntity4 = new AppParamEntity();
            appBalanceParamEntity4.setCode("BALANCE_FETCH_UNIT");
            appBalanceParamEntity4.setValue(appParamDO.getBalanceEftchUnit());
            appParamEntityList.add(appBalanceParamEntity4);
        }


        if(appParamDO.getType().equals("SIGNED")){
            AppParamEntity appSignedParamEntity1 = new AppParamEntity();
            appSignedParamEntity1.setCode("SIGNED_LOGO");
            appSignedParamEntity1.setValue(appParamDO.getSignedLogo());
            appParamEntityList.add(appSignedParamEntity1);


            AppParamEntity appSignedParamEntity5 = new AppParamEntity();
            appSignedParamEntity5.setCode("SIGNED_RULE");
            appSignedParamEntity5.setValue(JSON.toJSONString(appParamDO.getRules()));
            appParamEntityList.add(appSignedParamEntity5);
        }

        if(appParamDO.getType().equals("ORDER")){
            AppParamEntity appOrderParamEntity1 = new AppParamEntity();
            appOrderParamEntity1.setCode("ORDER_MESSAGE");
            appOrderParamEntity1.setValue(appParamDO.getOrderMessage());
            appParamEntityList.add(appOrderParamEntity1);
        }
        if(appParamDO.getType().equals("BIRTH")){
            AppParamEntity appBirthParamEntity1 = new AppParamEntity();
            appBirthParamEntity1.setCode("BIRTHDAY_ADVANCEDAYS");
            appBirthParamEntity1.setValue(appParamDO.getBirthdayAdvanceDays());
            appParamEntityList.add(appBirthParamEntity1);

            AppParamEntity appBirthParamEntity2 = new AppParamEntity();
            appBirthParamEntity2.setCode("BIRTHDAY_REMINDTIME");
            appBirthParamEntity2.setValue(appParamDO.getBirthdayRemindTime());
            appParamEntityList.add(appBirthParamEntity2);
        }

        return  appParamEntityList;
    }

    public static  AppParamDO changeAPLToAPD(List<AppParamEntity> appParamEntityList) {
        AppParamDO appParamDO = new AppParamDO();
        for (AppParamEntity appParamEntity : appParamEntityList) {
            if (appParamEntity.getCode().equals("SYS_LOGO")) {
                appParamDO.setSysLogo(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("SYS_TITLE")) {
                appParamDO.setSysTitle(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("SYS_QQ")) {
                appParamDO.setSysQQ(appParamEntity.getValue());
            }

            if (appParamEntity.getCode().equals("POINT_RATE")) {
                appParamDO.setPointRate(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("POINT_MAX")) {
                appParamDO.setPointMax(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("POINT_MIN")) {
                appParamDO.setPointMin(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("POINT_TOTALMAX")) {
                appParamDO.setPointTotalMax(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("POINT_TOTALTIME")) {
                appParamDO.setPointTotalTime(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("POINT_EXTRAMIN")) {
                appParamDO.setPointExtraMin(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("POINT_EXTRAMAX")) {
                appParamDO.setPointExtraMax(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("POINT_TOTAL_UNIT")) {
                appParamDO.setPointTotalUnit(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("POINT_TIME_UNIT")) {
                appParamDO.setPointTimeUnit(appParamEntity.getValue());
            }


            if (appParamEntity.getCode().equals("BALANCE_FETCH_TIMES")) {
                appParamDO.setBalanceEftchTimes(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("BALANCE_FETCH_MAX")) {
                appParamDO.setBalanceEftchMax(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("BALANCE_FETCH_MIN")) {
                appParamDO.setBalanceEftchMin(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("BALANCE_FETCH_UNIT")) {
                appParamDO.setBalanceEftchUnit(appParamEntity.getValue());
            }


            if (appParamEntity.getCode().equals("SIGNED_LOGO")) {
                appParamDO.setSignedLogo(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("SIGNED_RULE")) {
                List<SignRuleItem> list = JSONArray.parseArray(appParamEntity.getValue(),SignRuleItem.class);
                appParamDO.setRules(list);
            }



            if (appParamEntity.getCode().equals("ORDER_MESSAGE")) {
                appParamDO.setOrderMessage(appParamEntity.getValue());
            }

            if (appParamEntity.getCode().equals("BIRTHDAY_ADVANCEDAYS")) {
                appParamDO.setBirthdayAdvanceDays(appParamEntity.getValue());
            }
            if (appParamEntity.getCode().equals("BIRTHDAY_REMINDTIME")) {
                appParamDO.setBirthdayRemindTime(appParamEntity.getValue());
            }
        }
        return appParamDO;
    }




}
